package com.bicycle.rentalsystem.dao.impl.user;

import com.bicycle.rentalsystem.dao.UserDao;
import com.bicycle.rentalsystem.handler.SingleResultHandler;
import com.bicycle.rentalsystem.jdbc.JdbcUtil;
import com.bicycle.rentalsystem.pojo.user.User;

/**
 * 用户数据层实现类
 * 用于实现用户数据层接口
 * 目前不需要更改
 */
public class UserDaoImpl implements UserDao {
    @Override
    public User getUserByUsername(String username) {
        String sql = "SELECT username,password FROM user WHERE username=?";
        return JdbcUtil.query(sql,new SingleResultHandler<>(User.class),username);
    }

    @Override
    public Integer getIdentity(String username) {
        String sql = "SELECT COUNT(*) FROM role a INNER JOIN user_role b on a.id = b.role_id WHERE b.username = ? AND a.`name` = 'administrator'";
        Integer s = JdbcUtil.query(sql,new SingleResultHandler<>(Integer.class),username);
        return s;
    }


}
